import json
from datetime import datetime


class DateTimeEncoder(json.JSONEncoder):
    # default JSONEncoder cannot serialize datetime.datetime objects
    def default(self, obj):
        if isinstance(obj, datetime):
            encoded_object = obj.strftime('%Y-%m-%d %H:%M:%S')
        else:
            encoded_object = super(self, obj)
        return encoded_object
